package com.wx.nchu_mall.web;

import com.github.pagehelper.PageInfo;
import com.wx.nchu_mall.model.Orders;
import com.wx.nchu_mall.model.PageCondition;
import com.wx.nchu_mall.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



@RestController
public class OrdersController {
    @Autowired
    protected OrdersService ordersService;

    @PostMapping("/api/orders/findOrderList")
    public PageInfo<Orders> page(@RequestBody PageCondition<Orders> condition){
        return ordersService.page(condition);
    }

    @PostMapping("/api/orders/delete")
    public String delete(@RequestBody Orders orders){
        ordersService.deleteById(orders);
        return "success";
    }

    @PostMapping("/api/orders/sendOrder")
    public String sendOrder(@RequestBody Orders orders){
        ordersService.update(orders);
        return "success";
    }

    @PostMapping("/api/orders/getOrder")
    public List<Orders> getOrders(@RequestBody Orders orders){
        return ordersService.getOrders(orders);
    }

    @PostMapping("/api/orders/getOrderId")
    public Integer getOrderId(){
        return ordersService.getOrderId();
    }

    @PostMapping("/api/orders/addOrder")
    public String addOrder(@RequestBody Orders orders){
        ordersService.insert(orders);
        return "success";
    }

}
